/**
 *
 */
package com.zhuoyue.zhtj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.eit.eitsite.common.config.Global;
import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.web.BaseController;
import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.zhtj.entity.Kkcdtj;
import com.zhuoyue.zhtj.service.KkcdtjService;

/**
 * 旷课迟到信息Controller
 * @author hss
 * @version 2017-09-27
 */
@Controller
@RequestMapping(value = "${adminPath}/zhtj/kkcdtj")
public class KkcdtjController extends BaseController {

	@Autowired
	private KkcdtjService kkcdtjService;
	
	@ModelAttribute
	public Kkcdtj get(@RequestParam(required=false) String id) {
		Kkcdtj entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = kkcdtjService.get(id);
		}
		if (entity == null){
			entity = new Kkcdtj();
		}
		return entity;
	}
	
	@RequiresPermissions("zhtj:kkcdtj:view")
	@RequestMapping(value = {"list", ""})
	public String list(Kkcdtj kkcdtj, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Kkcdtj> page = kkcdtjService.findPage(new Page<Kkcdtj>(request, response), kkcdtj); 
		model.addAttribute("page", page);
		return "zhuoyue/zhtj/kkcdtjList";
	}

	@RequiresPermissions("zhtj:kkcdtj:view")
	@RequestMapping(value = "form")
	public String form(Kkcdtj kkcdtj, Model model) {
		model.addAttribute("kkcdtj", kkcdtj);
		return "zhuoyue/zhtj/kkcdtjForm";
	}

	@RequiresPermissions("zhtj:kkcdtj:edit")
	@RequestMapping(value = "save")
	public String save(Kkcdtj kkcdtj, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, kkcdtj)){
			return form(kkcdtj, model);
		}
		kkcdtjService.save(kkcdtj);
		addMessage(redirectAttributes, "保存旷课迟到信息成功");
		return "redirect:"+Global.getAdminPath()+"/zhtj/kkcdtj/?repage";
	}
	
	@RequiresPermissions("zhtj:kkcdtj:edit")
	@RequestMapping(value = "delete")
	public String delete(Kkcdtj kkcdtj, RedirectAttributes redirectAttributes) {
		kkcdtjService.delete(kkcdtj);
		addMessage(redirectAttributes, "删除旷课迟到信息成功");
		return "redirect:"+Global.getAdminPath()+"/zhtj/kkcdtj/?repage";
	}

}